<?php
class Banned_model extends CI_Model {

	function __construct()
    {
        parent::__construct();
    }

	public function add($data) {   
		$this->db->insert("banned", $data);
		return $this->db->insert_id();
	}
	
	public function update($data, $id) {
		$this->db->where('id', $id);
		$this->db->update('banned', $data); 
	}
	
	public function find_by_condition($condition, $offset = 0, $limit =20) {
		$sql = "select * from banned  
				where 1=1 " . $condition .
				" order by created desc limit " . $offset . "," . $limit;
		$result = $this->db->query($sql)->result_array();
		return $result;
	}
	
	public function has_post_priviledge($user_id) {
		$sql = "select count(*) as total from banned  
				where user_id=" . $user_id . " and type=1";
		$result = $this->db->query($sql)->row_array();
		return $result['total'] > 0 ? 0 : 1;
	}
}